<template>
  <div class="no-padding app-container">
    <lst-page-container>
      <template slot="query">
        <el-form :model="tableQueryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
          <el-form-item label="整改状态" prop="sceneState">
            <el-select v-model="tableQueryParams.sceneState">
              <el-option
                  v-for="dict in [{label:'待复核 ',value:'4'},{label:'复核通过 ',value:'6'},{label:'退回 ',value:'9'},]"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </template>

      <template slot="rowHandel">
        <el-button :disabled="multiple" type="primary" icon="el-icon-search" size="mini"
                   @click="audit(AUDIT_TYPE.pass,ids)">通过
        </el-button>
        <el-button :disabled="multiple" icon="el-icon-refresh" size="mini" @click="audit(AUDIT_TYPE.sendBack,ids)">
          退回
        </el-button>
      </template>

      <template slot="table">
        <el-table height="100%" @sort-change="handleSortChange" v-loading="loading" :data="dataList"
                  @selection-change="handleSelectionChange">
          <el-table-column type="selection" :selectable="selectable" width="55" align="center"/>
          <el-table-column :sortable="colum.sortable" v-for="(colum,index) in questionTableColum" :key="index"
                           :width="colum.width"
                           :label="colum.label"
                           :align="colum.align" :prop="colum.propValue">
            <template slot-scope="scope">
              <question-table-colum :scope="scope" :colum-config="colum"></question-table-colum>
            </template>
          </el-table-column>
          <el-table-column width="240" label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="showInfo(scope.row)"
              >查看
              </el-button>
              <el-button
                  v-if="scope.row.allowCheck  == 1"
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="audit(AUDIT_TYPE.pass,[scope.row.id])"
              >通过
              </el-button>
              <el-button
                  v-if="scope.row.allowCheck  == 1"
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="audit(AUDIT_TYPE.sendBack,[scope.row.id])"
              >退回
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>

      <template slot="pageDisplay">
        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="tableQueryParams.pageNum"
            :limit.sync="tableQueryParams.pageSize"
            @pagination="getList"
        />
      </template>
    </lst-page-container>


    <el-drawer
        class="diy-draw"
        title="隐患详情"
        :wrapperClosable="false"
        :size="HIDDEN_DANGER_WIDTH"
        :destroy-on-close="true"
        :visible.sync="infoOpen">
      <drawer-content>
        <template slot="body">
          <hidden-danger-info ref="danInfo" :info-data="infoData" :inspect-info="inspectInfo"></hidden-danger-info>
        </template>
        <template slot="footer" v-if="infoData.allowCheck  == 1">
          <el-button type="primary" icon="el-icon-search" size="mini"
                     @click="audit(AUDIT_TYPE.pass,[infoData.id])">通过
          </el-button>
          <el-button icon="el-icon-refresh" size="mini"
                     @click="audit(AUDIT_TYPE.sendBack,[infoData.id])">
            退回
          </el-button>
        </template>
      </drawer-content>
    </el-drawer>
  </div>
</template>

<script>
import {listPageMixins} from "@/mixins/listPageMixins";
import ShowFileList from "@/components/ShowFileList/index.vue";
import {subPageMixin} from "@/views/checkBusPage/mixins/subPageMixins";
import ChooseQuestion from "@/views/components/ChooseQuestion/index.vue";
import infoTable from "@/views/components/InfoTable/index.vue";
import {
  supLeaderCheckNoQuestion,
  supLeaderCheckOkQuestion,
  supLeaderGetQuestionDetail,
  supLeaderQueryQuestion
} from "@/api/checkPage/supLeader";
import {getQuestionDetail} from "@/api/checkPage/quertion";
import {HIDDEN_DANGER_WIDTH} from "@/constantData";
import HiddenDangerInfo from "@/views/checkBusPage/components/hiddenDangerInfo/index.vue";

export default {
  mixins: [listPageMixins, subPageMixin],
  components: {
    ShowFileList,
    ChooseQuestion,
    infoTable,
    HiddenDangerInfo
  },
  dicts: ['enum_question_repair'],
  data() {
    return {
      HIDDEN_DANGER_WIDTH,
      modelName: '自查隐患',
      AUDIT_TYPE: {
        pass: 'Y',
        sendBack: 'N'
      },
      // 查询参数
      queryParams: {
        // 整改状态
        sceneState: null,
        // 隐患类别
        questionTypeCode: null,
      },
      otherQueryParam: {
        inspectId: this.inspectInfo.id
      },
      getListFun: supLeaderQueryQuestion,
      getInfoFun: supLeaderGetQuestionDetail,
    }
  },
  methods: {
    selectable(row, index) {
      return row.allowCheck == 1
    },
    audit(type, questionIds) {
      let {AUDIT_TYPE} = this
      let owner = this
      this.$prompt('请输入审批说明', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
      }).then(({value: remark}) => {
        if (type == AUDIT_TYPE.pass) {
          supLeaderCheckOkQuestion({questionIds, remark}).then(res => {
            owner.$modal.msgSuccess("审核成功");
            owner.submitChange()
            questionIds.forEach(id =>{
              owner.reloadInfoData(id)
            })
            owner.getList()
          })
        } else {
          supLeaderCheckNoQuestion({questionIds, remark}).then(res => {
            owner.$modal.msgSuccess("审核成功");
            owner.submitChange()
            questionIds.forEach(id =>{
              owner.reloadInfoData(id)
            })
            owner.getList()
          })
        }
      }).catch(() => {
      });
    },
  }
}
</script>

<style scoped>

</style>
